﻿using Mammoth.Factories;
using Mammoth.Mappings;
using Mammoth.Reflections;
using Mammoth.Repositories;
using NHibernate.Mapping.ByCode.Conformist;

namespace Mammoth.Services
{
    public class AppInitializer : IAppInitializer
    {
        ITypeFactory factory;

        public AppInitializer(ITypeFactory factory)
        {
            this.factory = factory;
        }

        public void Initialize()
        {
            var config = factory.Create<IDatabaseConfiguration>();
            var db = factory.Create<IDataSessionFactory>();
            var mappings = typeof(EntityMapping<>).Assembly.GetExportedTypes()
                .GetTypesByBaseClass(typeof(ClassMapping<>));
            db.Configure(config, mappings);
        }
    }
}
